package com.trw.trp.bean;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class OrderBean {
	private String orderNumber;
	private long orderId = -1;
	private int status = 0;
	private String statusName;// only used for ui
	private String prjNumber;// only used for ui
	private String prjName;
	private int inputStatus;
	private String selectedModels;
	private Map<Integer, List<ModelBean>> modelMap;
	private Map<Integer, List<ModelDetail>> detailMap;
	private List<SampleInfo> sampleInfoList;
	private UserBean user;
	private Date createdDate;
	private GeneralInfo generalInfo;
	private List<MatrixInfo> matrixInfoList;
	private Map<String, OrderScheduleInfo> scheduleInfoMap;

	public enum OrderStatus {
		Unfinished("Unfinished"), PendingPipeline("Pending(Pipeline)"), Pipeline(
				"Pipeline"), PendingSample("Pending Sample(Pipeline)"), PendingGreenStatus(
				"Pending(Green Status)"), GreenStatus("Green Status"), InSchedule(
				"In Schedule"), Unknown("Unknown"), Rejected("Rejected"), PartialInSchedule(
				"Partial In Schedule"), PartialComplete("Partial Completed"), Completed(
				"Completed"), Canceled("Canceled");
		private String statusName;

		OrderStatus(String statusName) {
			this.statusName = statusName;
		}

		public String toString() {
			return statusName;
		}
	}

	public Map<String, OrderScheduleInfo> getScheduleInfoMap() {
		return scheduleInfoMap;
	}

	public void setScheduleInfoMap(
			Map<String, OrderScheduleInfo> scheduleInfoMap) {
		this.scheduleInfoMap = scheduleInfoMap;
	}

	public List<MatrixInfo> getMatrixInfoList() {
		return matrixInfoList;
	}

	public void setMatrixInfoList(List<MatrixInfo> matrixInfoList) {
		this.matrixInfoList = matrixInfoList;
	}

	public List<SampleInfo> getSampleInfoList() {
		return sampleInfoList;
	}

	public void setSampleInfoList(List<SampleInfo> sampleInfoList) {
		this.sampleInfoList = sampleInfoList;
	}

	public String getSelectedModels() {
		return selectedModels;
	}

	public void setSelectedModels(String selectedModels) {
		this.selectedModels = selectedModels;
	}

	public void generateOrderStatusName() {
		boolean isPending = false;
		if (status > 99) {
			isPending = true;
		}
		if (isPending) {
			switch (inputStatus) {
			case 1:
			case 2:
				statusName = OrderStatus.PendingPipeline.toString();
				break;
			case 3:
				statusName = OrderStatus.PendingSample.toString();
				break;
			default:
				statusName = OrderStatus.Unknown.toString();
			}
		} else {
			switch (status) {
			case -3:
				statusName = OrderStatus.Canceled.toString();
				break;
			case -2:
				statusName = OrderStatus.Rejected.toString();
				break;
			case 0:
				statusName = OrderStatus.Unfinished.toString();
				break;
			case 1:
			case 2:
				statusName = OrderStatus.Pipeline.toString();
				break;
			case 3:
				statusName = OrderStatus.PendingGreenStatus.toString();
				break;
			case 4:
				statusName = OrderStatus.GreenStatus.toString();
				break;
			case 10:
				statusName = OrderStatus.InSchedule.toString();
				break;
			case 11:
				statusName = OrderStatus.PartialInSchedule.toString();
				break;
			case 12:
				statusName = OrderStatus.PartialComplete.toString();
				break;
			case 13:
				statusName = OrderStatus.Completed.toString();
				break;
			default:
				statusName = OrderStatus.Unknown.toString();
			}
		}
	}

	public boolean isReadOnly(UserBean user, OrderStatus status) {
		boolean isReadOnly = true;
		if (user == null || user.getUserId() != this.user.getUserId()) {
			isReadOnly = false;
		} else {
			if (OrderStatus.Pipeline.equals(status)) {
				isReadOnly = this.status > 1;
			} else if (OrderStatus.GreenStatus.equals(status)) {
				isReadOnly = this.status > 2;
			}
		}
		return isReadOnly;
	}

	public String getStatusName() {
		return statusName;
	}

	public void setStatusName(String statusName) {
		this.statusName = statusName;
	}

	public GeneralInfo getGeneralInfo() {
		return generalInfo;
	}

	public void setGeneralInfo(GeneralInfo generalInfo) {
		this.generalInfo = generalInfo;
	}

	public UserBean getUser() {
		return user;
	}

	public void setUser(UserBean user) {
		this.user = user;
	}

	public String getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Map<Integer, List<ModelBean>> getModelMap() {
		return modelMap;
	}

	public void setModelMap(Map<Integer, List<ModelBean>> modelMap) {
		this.modelMap = modelMap;
	}

	public Map<Integer, List<ModelDetail>> getDetailMap() {
		return detailMap;
	}

	public void setDetailMap(Map<Integer, List<ModelDetail>> detailMap) {
		this.detailMap = detailMap;
	}

	public int getInputStatus() {
		return inputStatus;
	}

	public void setInputStatus(int inputStatus) {
		this.inputStatus = inputStatus;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public long getOrderId() {
		return orderId;
	}

	public void setOrderId(long orderId) {
		this.orderId = orderId;
	}

	public String getPrjNumber() {
		return prjNumber;
	}

	public void setPrjNumber(String prjNumber) {
		this.prjNumber = prjNumber;
	}

	public String getPrjName() {
		return prjName;
	}

	public void setPrjName(String prjName) {
		this.prjName = prjName;
	}

	public static class GeneralInfo {
		long id = -1;
		String customer;
		String project;
		String product;
		String plant;
		String phase;
		String projectNumber;
		String testPurpose;
		String reportMode;
		String reportDistribution;
		UserBean testUser;
		UserBean vvUser;
		String um;
		String jrt;
		String cp;
		String remarks;
		private String payer;

		public String getPlant() {
			return plant;
		}

		public void setPlant(String plant) {
			this.plant = plant;
		}

		public String getCustomer() {
			return customer;
		}

		public void setCustomer(String customer) {
			this.customer = customer;
		}

		public String getProject() {
			return project;
		}

		public void setProject(String project) {
			this.project = project;
		}

		public String getProduct() {
			return product;
		}

		public void setProduct(String product) {
			this.product = product;
		}

		public String getPhase() {
			return phase;
		}

		public void setPhase(String phase) {
			this.phase = phase;
		}

		public String getProjectNumber() {
			return projectNumber;
		}

		public void setProjectNumber(String projectNumber) {
			this.projectNumber = projectNumber;
		}

		public String getTestPurpose() {
			return testPurpose;
		}

		public void setTestPurpose(String testPurpose) {
			this.testPurpose = testPurpose;
		}

		public String getReportMode() {
			return reportMode;
		}

		public void setReportMode(String reportMode) {
			this.reportMode = reportMode;
		}

		public String getReportDistribution() {
			return reportDistribution;
		}

		public void setReportDistribution(String reportDistribution) {
			this.reportDistribution = reportDistribution;
		}

		public UserBean getTestUser() {
			return testUser;
		}

		public void setTestUser(UserBean testUser) {
			this.testUser = testUser;
		}

		public UserBean getVvUser() {
			return vvUser;
		}

		public void setVvUser(UserBean vvUser) {
			this.vvUser = vvUser;
		}

		public String getUm() {
			return um;
		}

		public void setUm(String um) {
			this.um = um;
		}

		public String getJrt() {
			return jrt;
		}

		public void setJrt(String jrt) {
			this.jrt = jrt;
		}

		public String getCp() {
			return cp;
		}

		public void setCp(String cp) {
			this.cp = cp;
		}

		public String getRemarks() {
			return remarks;
		}

		public void setRemarks(String remarks) {
			this.remarks = remarks;
		}

		public long getId() {
			return id;
		}

		public void setId(long id) {
			this.id = id;
		}

		public void setPayer(String payer) {
			this.payer = payer;
		}

		public String getPayer() {
			return payer;
		}

	}

	public static class MatrixInfo {
		String clientUniqueId;
		List<List<ModelDetail.Field>> fieldList;

		public String getClientUniqueId() {
			return clientUniqueId;
		}

		public void setClientUniqueId(String clientUniqueId) {
			this.clientUniqueId = clientUniqueId;
		}

		public List<List<ModelDetail.Field>> getFieldList() {
			return fieldList;
		}

		public void setFieldList(List<List<ModelDetail.Field>> fieldList) {
			this.fieldList = fieldList;
		}
	}

	public static class SampleInfo {
		String clientUniqueId;
		Map<Long, List<List<ModelDetail.Field>>> fieldListMap;

		public Map<Long, List<List<ModelDetail.Field>>> getFieldListMap() {
			return fieldListMap;
		}

		public void setFieldListMap(
				Map<Long, List<List<ModelDetail.Field>>> fieldListMap) {
			this.fieldListMap = fieldListMap;
		}

		public String getClientUniqueId() {
			return clientUniqueId;
		}

		public void setClientUniqueId(String clientUniqueId) {
			this.clientUniqueId = clientUniqueId;
		}

	}

	@Override
	public String toString() {
		return "OrderBean [orderNumber=" + orderNumber + ", orderId=" + orderId
				+ ", status=" + status + ", statusName=" + statusName
				+ ", inputStatus=" + inputStatus + ", selectedModels="
				+ selectedModels + ", modelMap=" + modelMap + ", detailMap="
				+ detailMap + ", sampleInfoList=" + sampleInfoList + ", user="
				+ user + ", createdDate=" + createdDate + ", generalInfo="
				+ generalInfo + ", matrixInfoList=" + matrixInfoList
				+ ", scheduleInfoMap=" + scheduleInfoMap + "]";
	}

}
